package test.baojia.act.business;

import com.alibaba.fastjson.JSONObject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.testng.Assert;
import test.baojia.act.operation.Operation;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

/**
 * 保存后，判断报价单基本信息中文本框和复选框是否只读。
 */
public class SaveAndFullFormReadonlyBusiness extends FullFormReadonlyBusiness {

    @Override
    public void run(JSONObject context, WebDriver driver, Properties resource, JSONObject parentContext) throws  Exception {
        Thread.sleep(Long.valueOf(resource.getProperty("submit.sleep")) * 1000);

        super.run(context, driver, resource, parentContext);

        String projectCode = driver.findElement(By.id("projectCode")).getAttribute("value");

        String businessType = driver.findElement(By.id("businessType")).getAttribute("value");
        String year = new SimpleDateFormat("yyyy").format(new Date());
        String userCode = context.getString(Operation.OPERATION.byValue.toString());
        String projectCodePrefix = userCode + year + businessType;

        Assert.assertTrue(
                projectCode.startsWith(projectCodePrefix) ,
                "Project No is wrong." + projectCode + "<=>" + projectCodePrefix);

        this.logger.info("Project Code : {}" , projectCode);

        this.newWebDriverWait(null).until(
                ExpectedConditions.presenceOfElementLocated(By.id("backTaskBtn"))
        );
    }
}
